//Program by:
//Ben Schmidt - bjs778 - 11054018
//Mike Nimeck - mfn028 - 11053045
//Jeff Huang - jlh105 - 11050226
//
//Fully implemented by hand, but OpenGL SuperBible example
//used heavily as reference

// Flocking render vertex shader
#version 330

// Model-view-projection matrix
uniform mat4 mvp;
uniform int base_size;
uniform float depth_divisor;

// Instanced attributes (position and velocity of the flock member)
layout (location = 0) in vec3 instance_position;
layout (location = 1) in vec3 instance_velocity;
layout (location = 2) in vec3 instance_mass;

// Output color from the vertex shader
flat out vec4 vs_color;

void main(void)
{
    vec4 pos = vec4(instance_position, 1.0);
    
    float current_mass = (instance_mass.x / 100000);
    float scale = (instance_mass.x / 100000);
    
    float size = base_size - (instance_position.z / depth_divisor);
    if (size > 1.0f){
	gl_PointSize = size;
    }
    else {
	gl_PointSize = 1.0f;
    }
    
    vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
    
    if (current_mass > 0.6f)
    {
	color[0] = 1.0f;
	color[1] = 0.0f;
	color[2] = 0.0f;
    }
    else if (current_mass > 0.3f)
    {
	color[0] = 1.0f;
	color[1] = 1.0f;
	color[2] = 0.0f;	    
    }
    else if (current_mass >= 0.0f)
    {
	color[0] = 0.0f;
	color[1] = 1.0f;
	color[2] = 0.0f;
    }
    
    vs_color = color;

    //vs_color = vec4(current_mass, 0.0f, 0.0f, 1.0f);
    
    // Output position
    gl_Position = mvp * pos;
}
